import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
export 'package:pull_to_refresh/pull_to_refresh.dart';

class UiPushToRefresh extends StatelessWidget {
  const UiPushToRefresh({
    super.key,
    required this.controller,
    this.scrollController,
    this.enablePullDown,
    this.enablePullUp,
    this.enableTwoLevel,
    this.onRefresh,
    this.onLoad,
    this.onTwoLevel,
    this.child,
    this.footer,
    this.header,
  });
  final RefreshController controller;
  final ScrollController? scrollController;
  final Widget? child;
  final Widget? header;
  final Widget? footer;
  final bool? enablePullDown;
  final bool? enablePullUp;
  final bool? enableTwoLevel;
  final Function()? onRefresh;
  final Function()? onLoad;
  final Function(bool)? onTwoLevel;

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
      controller: controller,
      scrollController: scrollController,
      enablePullDown: enablePullDown ?? onRefresh != null,
      enablePullUp: enablePullUp ?? onLoad != null,
      enableTwoLevel: enableTwoLevel ?? onTwoLevel != null,
      onRefresh: onRefresh,
      onLoading: onLoad,
      onTwoLevel: onTwoLevel,
      header: header ??
          const ClassicHeader(
            refreshingIcon: SizedBox(
              width: 16,
              height: 16,
              child: CircularProgressIndicator(
                strokeWidth: 2,
                color: Colors.grey,
              ),
            ),
            releaseIcon: Icon(Icons.arrow_upward, color: Colors.grey),
            idleText: "下拉刷新",
            releaseText: '释放刷新',
            refreshingText: '正在刷新',
            completeText: '刷新成功',
          ),
      footer: footer ??
          const ClassicFooter(
            idleText: '上拉加载',
            noDataText: "加载完毕",
            loadingText: '正在加载',
            canLoadingText: '释放加载',
            loadingIcon: SizedBox(
              width: 16,
              height: 16,
              child: CircularProgressIndicator(
                strokeWidth: 2,
                color: Colors.grey,
              ),
            ),
          ),
      child: child,
    );
  }
}
